<template>
    <div>

       
        <el-menu
            default-active="2"
            class="el-menu-vertical-demo"
            :collapse="collapse"
            @open="handleOpen"
            @close="handleClose"
        >
              <div  v-for="item in mData" :index="item.path" :key="item.path">
                <el-sub-menu  v-if="item.children && item.children.length > 0 " :index="item.path" :key="item.path">
                    <!-- 第一层渲染  -->
                    <template #title>
                        <component v-if="item.icon" :is="`mo-icon-${item.icon}`" />
                        <span>{{ item.name }}</span>
                    </template>
                    <!-- 第二层渲染 -->
                    <span  v-for="item2 in item.children" :index="item2.path" :key="item2.path">
                        <el-menu-item :index="item2.path">
                            <component v-if="item2.icon" :is="`mo-icon-${item2.icon}`" />
                            <template #title>{{ item2.name }}</template>
                        </el-menu-item>
                    </span>
                    <!-- 第三层是重复性工作了，先只设计2层的 -->
                </el-sub-menu>
                <!-- 第一层部不带子集 -->
                 <el-menu-item v-else :index="item.path">
                    <component v-if="item.icon" :is="`mo-icon-${item.icon}`" />
                    <template #title>{{ item.name }}</template>
                </el-menu-item>
              </div>
        </el-menu>
  </div>
</template>

<script lang="ts" setup>
import { ref } from 'vue'

import { menuData } from "./demoData";
const mData = ref(menuData) ;

//! 父对象传入属性？
let props = defineProps<{
    collapse:boolean
}>();


// import { useRequest } from "vue-request"
// 请求接口 /api/get
// const objectService = {
//   url: '/mock/getMenu',
//   method: 'POST',
//   headers: new Headers({
//     'Content-Type': 'application/json',
//   }),
// };

//  const { run , data , loading, error } = useRequest(objectService);
//  console.log(data);

const isCollapse = ref(false)
const handleOpen = (key: string, keyPath: string[]) => {
  console.log(key, keyPath)
}
const handleClose = (key: string, keyPath: string[]) => {
  console.log(key, keyPath)
}
</script>

<style>
/*** 配置展开时的属性 */
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;  
  min-height: 400px;
}
</style>